const http = require("http");

// get的请求
(function () {
  return;
  const request = http.request(
    "http://www.baidu.com",
    {
      method: "GET",
    },
    (res) => {
      // console.log(res.statusCode);
      // console.log(res.headers);
      let resp = "";
      res.on("data", (chunk) => {
        console.log(chunk);
        resp += chunk.toString("utf-8");
      });
      res.on("close", (chunk) => {
        console.log("关闭了", resp);
      });
    }
  );

  request.end(); // 消息体结束
})();
// gei请求测试2
(function () {
  return;
  const request = http.request(
    "http://yuanjin.tech:5005/api/movie",
    {
      method: "GET",
    },
    (res) => {
      // console.log(res.statusCode);
      // console.log(res.headers);
      let resp = "";
      res.on("data", (chunk) => {
        console.log(chunk);
        resp += chunk.toString("utf-8");
      });
      res.on("close", (chunk) => {
        console.log("关闭了", JSON.parse(resp));
      });
    }
  );

  request.end(); // 消息体结束
})();

//// gei请求测试3
(function () {
  // return;
  const request = http.request(
    "http://localhost:1234/css/index.css",
    {
      method: "GET",
    },
    (res) => {
      // console.log(res.statusCode);
      // console.log(res.headers);
      let resp = "";
      res.on("data", (chunk) => {
        console.log(chunk);
        resp += chunk.toString("utf-8");
      });
      res.on("close", (chunk) => {
        console.log("关闭了", resp);
      });
    }
  );

  request.end(); // 消息体结束
})();
